package binarytree

// 前序遍历 递归写法
func RecursiveTraversalPreorder(root *TreeNode) []int {
	result := []int{}
	return preorderDo(root, result)
}

func preorderDo(root *TreeNode, result []int) []int {
	if root == nil {
		return result
	}

	result = append(result, root.Val)
	result = preorderDo(root.Left, result)
	result = preorderDo(root.Right, result)
	return result
}

func RecursiveTraversalInorder(root *TreeNode) []int {
	result := []int{}
	return inorderDo(root, result)
}
func inorderDo(root *TreeNode, result []int) []int {
	if root == nil {
		return result
	}

	result = inorderDo(root.Left, result)
	result = append(result, root.Val)
	result = inorderDo(root.Right, result)
	return result
}
func RecursiveTraversalPostorder(root *TreeNode) []int {
	result := []int{}
	return postorderDo(root, result)
}
func postorderDo(root *TreeNode, result []int) []int {
	if root == nil {
		return result
	}

	result = postorderDo(root.Left, result)
	result = postorderDo(root.Right, result)
	result = append(result, root.Val)
	return result
}
